/**
 * @param {number[]} nums
 * @return {number[][]}
 */
 var permute = function(nums) {
    let res =[],curr=[],length=nums.length;
    function tools(){
        if(curr.length==length){
            res.push([...curr])
            return 
        }
        let set = new Set(curr)
        for(let i=0;i<length;i++){
            if(set.has(nums[i])) continue
            curr.push(nums[i])
            tools()
            curr.pop() 
        }
    }
    tools()
    return res
};